package com.imooc.security.demo.Filter;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;
import java.util.Date;

/**
 * @author JackYang
 * @description:
 * @create: 2020/6/13 23:29
 */
//@Component
public class TimeFilter implements Filter {
    
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("filter, init......");
    }
    
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("filter, doFilter......time filter start!");
        long starter = System.currentTimeMillis();
        //执行controller中的方法
        filterChain.doFilter(servletRequest, servletResponse);
        long end = System.currentTimeMillis();
        System.out.println("filter,time filter end! -----共耗时："+(end-starter));
    }
    
    @Override
    public void destroy() {
        System.out.println("filter, destroy......");
    }
}
